<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <title>优客书城</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" th:href="@{/css/theme-chalk.css}">
    <link rel="stylesheet" th:href="@{/css/login_style.css}">
</head>

<body class="mainBg">
    <div id="app">
	<form class="loginForm clear" id="loginForm" action="" >
        <div class="loginMain">
          <div class="loginlogo"></div>
          <div class="loginCon">
              <span class="el-form-item">
                <span class="userIcon"></span>
                <span class="el-input">
                  <input class="el-input__inner" name="username" id="username" placeholder="管理员账号"/>
                </span>
              </span>
              <span class="el-form-item">
                <span class="pwdIcon"></span>
                <span class="el-input">
                  <input class="el-input__inner" name="password" id="password" type="password" placeholder="密码"/>
                </span>
              </span>
          </div>

          <div class="loginBtn">
              <input type="button" class="el-button el-button--primary" value="登录" th:onclick="|login()|">
          </div>
        </div>
	</form>

    </div>
</body>

<script src="dist/js/jquery.min.js" th:src="@{/dist/js/jquery.min.js}"></script>
<script src="js/md5.js" th:src="@{/js/md5.js}"></script>
<script>
    window.onload = windowHeight; //页面载入完毕执行函数
    function windowHeight() {
        var asieHeight=document.getElementById("app")
        asieHeight.style.height=document.documentElement.clientHeight + 'px'
    }


    function login() {
        var pwd = hex_md5(document.getElementById("password").value);
        var name = document.getElementById("username").value;
        var datas = {"username": name, "password": pwd};
        $.ajax({
            url: "/admin/login",
            data: datas,
            method: "post",
            success: function (data) {
                if(data == '100'){
                    window.location.href = "/admin/index"; //返回首页
                }else if(data == '101') {
                    $("#username").val("用户名不存在"); //显示用户名提示信息
                    $("#username").css("color", "red");
                }else {
                    $("#password").val("密码错误"); //显示密码提示信息
                    $("#password").css("color", "red");
                }
            }
        })
    }
</script>
</html>
